#!/usr/bin/python
# -*- coding: utf-8 -*-

import subprocess
import os
import re

## Generate config_local file
config_local = """ 
# Config file for llcomp

# Current work dir
WORKDIR="<dir>"


# Location of cuda files
CUDA_INSTALL_DIR="/usr/local/cuda/"

LEX_OPTIMIZE=True
YACC_OPTIMIZE=True
"""
print 'Writing config file ........ ',
pwd = os.getcwd()
config_local = re.sub("<dir>", pwd+'/', config_local)
fconfig = open('config_local.py', 'w')
fconfig.write(config_local)
fconfig.close()
print '[ok]'

# Generating AST
print 'Generating ast ......',
dir_config_frontend = "./yacf/Frontend/"
os.chdir(dir_config_frontend)
f = open("./loginstall",'w')
subprocess.call("python _ast_gen.py", shell=True, stdout=f)
print '[ok]'

# export PYTHONPATH
print 'Writing in bashrc ....',
export = "export PYTHONPATH=" + pwd + ":$PYTHONPATH"
subprocess.call(export, shell=True, stdout=f)
bashrc = open(os.environ['HOME']+'/.bashrc','a+')
bashrc.write(export)
bashrc.close()
print '[ok]'
        
        